package cn.fintecher.pangolin.service.manage.web;

import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.entity.elastic.SystemLog;
import cn.fintecher.pangolin.entity.elastic.SystemLoginLog;
import cn.fintecher.pangolin.service.manage.request.FindLoginRequest;
import cn.fintecher.pangolin.service.manage.request.FindSystemLogRequest;
import cn.fintecher.pangolin.service.manage.service.SystemLogService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 系统日志相关接口
 * @Date: 15:17 2019/8/23
 */

@RestController
@RequestMapping("/api/systemLogController")
@Api(value = "系统日志相关接口", description = "系统日志相关接口")
public class SystemLogController extends BaseController {
    @Autowired
    private SystemLogService systemLogService;

    /**
     * 系统登录日志查询
     */
    @ApiOperation(value = "系统登录日志查询", notes = "系统登录日志查询")
    @GetMapping("/findAllLoginLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<SystemLoginLog>> findAllLoginLog(FindLoginRequest request,
                                                                Pageable pageable) {
        log.info("REST request to find all login log,{}", request);
        Page<SystemLoginLog> page = systemLogService.findAllLoginLog(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 批量删除登录日志
     */
    @ApiOperation(value = "批量删除登录日志", notes = "批量删除登录日志")
    @DeleteMapping("/batchDeleteLog")
    public ResponseEntity<Void> batchDeleteLog(@RequestParam @ApiParam(value = "日志ID集合") List<String> ids) {
        log.info("REST request to batch delete log,{}", ids);
        systemLogService.batchDeleteLog(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 系统日志查询
     */
    @ApiOperation(value = "系统日志查询", notes = "系统日志查询")
    @GetMapping("/findAllSystemLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<SystemLog>> findAllSystemLog(FindSystemLogRequest request, Pageable pageable) {
        log.info("REST request to find all system log,{}", request);
        Page<SystemLog> page = systemLogService.findAllSystemLog(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 批量删除系统日志
     */
    @ApiOperation(value = "批量删除系统日志", notes = "批量删除系统日志")
    @DeleteMapping("/batchDeleteSystemLog")
    public ResponseEntity<Void> batchDeleteSystemLog(@RequestParam @ApiParam(value = "日志ID集合") List<String> ids) {
        log.info("REST request to batch delete system log,{}", ids);
        systemLogService.batchDeleteSystemLog(ids);
        return ResponseEntity.ok().build();
    }
}